using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SchoolsBI;
using System.Xml;

public partial class Profesores_Resumen : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CboReunion.seleciona += new cboSelected(CboReunion_seleciona);
        CursoSeleccion1.seleciona += new CursoSelected(CursoSeleccion1_seleciona);
        if (!IsPostBack)
        {
            FillCboReuniones();
            
        }
    }

    void CursoSeleccion1_seleciona(Periodos Periodo)
    {
        ShowGrid();

    }




  #region Actualizar Combos
    
    private void FillCboReuniones()
    {
        CboReunion.SourceData = "Proc_getReunionesConcepto ";
        CboReunion.TipoOrigen = Controles_cboGeneric.TipoSource.Procedure;
        CboReunion.NameId = "Id";
        CboReunion.NameDescript = "Detalle";
        CboReunion.BindCBO();

    }
#endregion

    #region Eventos
    
    void CboReunion_seleciona(string param1, string param2)
    {
        //intentar buscar la reunion en funcion de la    
        ShowGrid();

    }
    
    #endregion
  

    private void ShowGrid()
    {

        if (CboReunion.ValueInt > 0 && biFactory.IdMateria > 0 && biFactory.IdCurso > 0)
        {
            string sP = "proc_getConcepto " + CboReunion.Value + ", " + biFactory.IdMateria + ", " + biFactory.IdCurso;
            Label1.Text = sP;
            //Label1.Visible = true;
            DataTable dt = Colegio.Tabla(sP);
            GridView1.DataSource = dt;
            GridView1.DataBind();
            GridView1.Visible = true;
            cmdGuardar.Visible = true;
        }
        else {
            GridView1.Visible = false;
            cmdGuardar.Visible = false;
        }
    }
 

    protected void cmdGuardar_Click(object sender, EventArgs e)
    {
        //primero guardarmos la reunion
        SchoolsBI.ConceptoReunionMateria cm = new ConceptoReunionMateria();

        cm.IdMateria = biFactory.IdMateria;
        cm.IdProfesor = biFactory.IdCurso;
        cm.IdReunion = CboReunion.ValueInt;
        cm.Fecha = System.DateTime.Now;
        cm.Observacion = "nuevita";
        string sError = cm.Crear();
        Label1.Text = sError;
            foreach (GridViewRow rg in GridView1.Rows)
            {
                Controles_cboNumerico cNota1 = ((Controles_cboNumerico)(rg.FindControl("CboNumerico1")));
                Controles_cboNumerico cNota2 = ((Controles_cboNumerico)(rg.FindControl("CboNumerico2")));
                string sObser; // = ((TextBox)rg.FindControl("TxtObervacion")).Text;
                //if (sObser.Length == 0) { sObser = "Nota Conceptual"; }
                sObser = "Nota Conceptual";
                if (!cNota1.Borrado || !cNota2.Borrado)
                {
                    SaveDS(Convert.ToInt32(GridView1.DataKeys[rg.RowIndex].Value.ToString()), cNota1.Value, cNota2.Value, sObser, cm.IdConceptoReunion);
                }
                else
                {
                    EliminarNota(Convert.ToInt32(GridView1.DataKeys[rg.RowIndex].Value.ToString()), cm.IdConceptoReunion);
                }
            }

            ShowGrid();

    }
    private void EliminarNota(int IdAlumnoCurso, int IdReunion)
    {
        try
        {
            
            SchoolsBI.ConceptoNota n = ConceptoNota.Buscar("IdAlumnoCurso =" + IdAlumnoCurso + " and IdProfesor = " + biFactory.IdCurso + " and idreunion = " + IdReunion);
            n.Borrar();
        }
        catch (Exception ex)
        {
        }

    }
    private void SaveDS(Int32 IdAlumnoCurso, Single nota1,Single nota2, String Obser, Int32 idConceptoReunion)
    {
        if (nota1 > -1 || nota2>-1)
        {
            SchoolsBI.ConceptoNota n = new ConceptoNota();
            
            n.Rendimiento = Convert.ToDecimal( nota1);
            n.IdReunion = idConceptoReunion;
            n.IdMateria = biFactory.IdMateria;
            n.Actitud = Convert.ToDecimal( nota2);
            n.IdAlumnoCurso = IdAlumnoCurso;
            n.Crear();
        }

    }
    protected void CboReunion_Load(object sender, EventArgs e)
    {

    }
}